﻿Imports Cls_Common
Imports VSModel
Imports System.Data

Partial Class FrontEnd_Control_TinMuaXe_TinMuaXeSEO
    Inherits System.Web.UI.UserControl
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Page.Title = "mua xe oto cu tai tphcm | oto sai thanh"
        Page.MetaDescription = "cần mua xe oto cu tphcm, cần mua gấp xe oto cũ giá rẻ tphcm"
        Page.MetaKeywords = "cần mua xe ô tô cũ chính chủ tại tphcm, can mua gap xe oto cu tai tphcm"

        BindToGrid(1, 13)
    End Sub
    

    



    Private Sub BindToGrid(ByVal ipage As Integer, ByVal _TinhThanhId As Integer)
        Using Data As New VSEntities

            Dim p As List(Of TinMuaXe)

            p = (From q In Data.TinMuaXes Where q.StatusId = 3 And q.PublishedDate <= Now() And (q.eEffectiveDate >= Now() _
                                                Or q.eEffectiveDate Is Nothing) And (q.User.TinhTP = _TinhThanhId Or _TinhThanhId = 0) _
                                            Order By q.Modified Descending, q.Created Descending Select q).Take(30).ToList

    

            With rptProduct
                .DataSource = p
                .DataBind()
            End With

        End Using
    End Sub

    Protected Sub rtpProduct_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptProduct.ItemDataBound
        Dim row As VSModel.TinMuaXe = CType(e.Item.DataItem, VSModel.TinMuaXe)

        Dim hplTitle As HyperLink = CType(e.Item.FindControl("hplTitle"), HyperLink)

        hplTitle.Text = row.TieuDe & " - " & row.TinMuaXeKhoangGia.Title
        '  hplTitle.NavigateUrl = MainDomain & row.QueryString & "-" & row.RaovatId.ToString & ".html"
        Dim ltrDescription As Literal = CType(e.Item.FindControl("ltrDescription"), Literal)
        ltrDescription.Text = CropText(row.NoiDung, 300, "...")
   
        Dim ltrLienHe As Literal = CType(e.Item.FindControl("ltrLienHe"), Literal)

        Dim ltrTelephone As Literal = CType(e.Item.FindControl("ltrTelephone"), Literal)
        ltrLienHe.Text = row.LienHe & "<br/>Địa Chỉ: " & row.DiaChi
        ltrTelephone.Text = row.SoDienThoai

        If Not row.User.MobileOrther Is Nothing AndAlso row.User.MobileOrther <> "" Then
            ltrTelephone.Text = ltrTelephone.Text & " - " & row.User.MobileOrther
        End If

        'Dim ltrMaTin As Literal = CType(e.Item.FindControl("ltrMaTin"), Literal)
        'ltrMaTin.Text = row.MaTin
        Dim ltrTinhThanh As Literal = CType(e.Item.FindControl("ltrTinhThanh"), Literal)
        If Not IsNothing(row.UserId) Then
            ltrTinhThanh.Text = GetTinhThanhPho(row.TinhThanhId)
        End If
    End Sub


    Private Function GetTinhThanhPho(ByVal _TinhThanhId As Integer) As String
        Using _data As New VSEntities
            Dim p = (From q In _data.DonViHanhChinhs Where q.Id = _TinhThanhId Select q.Title).FirstOrDefault
            If Not p Is Nothing Then
                Return p
            End If

        End Using
        Return ""
    End Function


End Class
